<?php

class Resource {
	private $id;
	private $id_subcategory;
	private $path;
	private $title;
	private $description;
	private $id_type;
	private $id_user;
	
	function __construct($id,$id_subcategory,$path,$title,$description,$id_type,$id_user){
		$this -> id 			= $id;
		$this -> id_subcategory = $id_subcategory;
		$this -> path 			= $path;
		$this -> title 			= $title;
		$this -> description 	= $description;
		$this -> id_type 		= $id_type;
		$this -> id_user 		= $id_user;
	}
	
	function getResource($db,$id){
		$result		= $db->query("SELECT * FROM resource WHERE res_IDresource = $id",2);
		$resource 	= new Resource(	$result[0]['res_IDresource'],
						$result[0]['res_id_subcategory'], 
						$result[0]['res_path'],
						$result[0]['res_title'],
						$result[0]['res_description'],
						$result[0]['res_id_type'],
						$result[0]['res_id_user']);
		return $resource;
	}
	/*Insert*/
	function insert($db,$resource){
		$id_subcategory = $resource -> getIDsubcategory();
		$path			= $resource -> getPath();
		$title 			= $resource -> getTitle();
		$description 	= $resource -> getDescription();
		$id_type 		= $resource -> getIDtype();
		$id_user 		= $resource -> getIDuser();
		$result=$db->insert("INSERT INTO resource (res_id_subcategory,res_path,res_title,_res_description,res_id_type,res_id_user)
										 VALUES($id_subcategory,'$path','$title','$description',$id_type,$id_user");
		return $result;
	}
	/*Delete*/
	function delete($db,$resource){
		$id 	= $resource -> getIDresource();
		$result = $db -> delete("DELETE FROM resource WHERE res_IDresource = $id");
		return $result;
	}
	/*Modify*/
	function update($db,$resource){
		$id 			= $resource -> getIDresource();
		$id_subcategory = $resource -> getIDsubcategory();
		$path			= $resource -> getPath();
		$title 			= $resource -> getTitle();
		$description 	= $resource -> getDescription();
		$id_type 		= $resource -> getIDtype();
		$id_user 		= $resource -> getIDuser();
		$result = $db -> update ("UPDATE resource SET res_id_subcategory 	= $id_subcategory, 
													  res_path 				= '$path', 
													  res_title 			= '$title', 
													  res_description 		= '$description', 
													  res_id_type 			= $id_type, 
													  res_id_user 			= $id_user 
													  WHERE res_IDresource = $id");
		
	}
	
	/*ID resource*/
	function getIDresource(){
		return $this -> id;
	}	
	function setIDresource($id){
		$this -> id = $id;
	}	
	/*ID subcategory*/
	function getIDsubcategory(){
		return $this -> id_subcategory;
	}	
	function  setIDsubcategory($id_subcategory){
		$this -> id_subcategory = $id_subcategory;
	}	
	/*Path*/
	function getPath(){
		return $this -> path;
	}	
	function  setPath($email){
		$this -> path = $path;
	}	
	/*Title*/
	function getTitle(){
		return $this -> title;
	}
	function  setTitle($title){
		$this -> title = $title;
	}
	/*Description*/
	function getDescription(){
		return $this -> description;
	}
	function  setDescription($description){
		$this -> description = $description;
	}
	/*ID type*/
	function getIDtype(){
		return $this -> id_type;
	}
	function  setIDtype($id_type){
		$this -> id_type = $id_type;
	}
	/*ID user*/
	function getIDuser(){
		return $this -> id_user;
	}
	function  setIDuser($id_user){
		$this -> id_user = $id_user;
	}
	
}

?>